// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher

import { secretId, secretKey } from "../../config/secret";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const tencentcloud = require("tencentcloud-sdk-nodejs");

const NlpClient = tencentcloud.nlp.v20190408.Client;

const clientConfig = {
  credential: {
    SecretId: secretId,
    SecretKey: secretKey,
  },
  region: "ap-guangzhou",
  profile: {
    httpProfile: {
      endpoint: "nlp.tencentcloudapi.com",
    },
  },
};

const client = new NlpClient(clientConfig);

// 智能机器人 https://console.cloud.tencent.com/nlp/basicguide
// https://console.cloud.tencent.com/api/explorer?Product=nlp&Version=2019-04-08&Action=ChatBot&SignVersion=
export default function getRobotTextService(text: string) {
  return new Promise((resolve, reject) => {
    client.ChatBot({
      Query: text,
    })
    .then((data: IAnyObject) => {
        resolve(data)
      })
    .catch((error: any) => {
      reject(error)
    })
  })
}